package org.tigris.atlas.quizme.client.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.tigris.atlas.messages.Message;
import org.tigris.atlas.messages.MessageFactory;
import org.tigris.atlas.messages.MessageUtils;
import org.tigris.atlas.messages.Messages;
import org.tigris.atlas.quizme.client.form.LoginForm;
import org.tigris.atlas.quizme.client.utils.ClientUtils;

/**
 * Log the user out.
 * 
 * @author Robert Simmering
 */
public class LogoutAction  extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
		      HttpServletRequest request, HttpServletResponse response) {	
		request.getSession().invalidate();
		Message msg = MessageUtils.createInformationalMessage("success.logout", null, null);
		Messages messages = MessageFactory.createMessages();
		messages.addMessage(msg);
		ClientUtils.getMessagesHandler().handleMessages(messages, LoginForm.class, request);
		return mapping.findForward("success");
	}
}